package com.geeklan.smart.ui.pet.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.geeklan.smart.R;
import com.geeklan.smart.databinding.AdapterCaseImageItemBinding;
import com.geeklan.smart.databinding.AdapterCastListItemBinding;

import java.util.List;

public class CasePhotoAdapter extends RecyclerView.Adapter<CasePhotoAdapter.PhotoViewHolder> {
    private final Context context;
    private final String[] urls; // 图片路径列表

    public CasePhotoAdapter(Context context, String[] urls) {
        this.context = context;
        this.urls = urls;
    }

    @NonNull
    @Override
    public CasePhotoAdapter.PhotoViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        AdapterCaseImageItemBinding adapterCaseImageItemBinding = AdapterCaseImageItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new PhotoViewHolder(adapterCaseImageItemBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull CasePhotoAdapter.PhotoViewHolder holder, int position) {
        String photoPath = urls[position]; // 计算图片索引
        Glide.with(context).load(photoPath).into(holder.mbinding.ivCaseImageItem);
    }

    @Override
    public int getItemCount() {
        return urls.length;
    }

    public static class PhotoViewHolder extends RecyclerView.ViewHolder {
        AdapterCaseImageItemBinding mbinding;

        public PhotoViewHolder(@NonNull AdapterCaseImageItemBinding itemView) {
            super(itemView.getRoot());
            mbinding = itemView;
        }
    }
}
